<template>
	<div class='app-container'>
		<el-row :gutter="20" style="margin-bottom: 12px;">
			<el-col :span="8">
		        <el-input v-model.trim="listQuery.wordName" type="text" placeholder="请输入搜索内容" @keyup.enter.native="getList" clearable>
		          	<el-button slot="append" icon="el-icon-search" @click='getList'></el-button>
		        </el-input>
	        </el-col>
			<el-col :span="2">
				<el-button @click="handleDeleteList" type="danger">移出黑名单</el-button>
			</el-col>
		</el-row>
		<el-table :data="tableData" v-loading="listLoading" element-loading-text="加载中..." border fit highlight-current-row @selection-change="handleSelectionChange" style="width: 100%">
			<el-table-column align="center" type="selection" width="55"></el-table-column>
			<el-table-column prop="wordName" label="词汇名称" align="center"></el-table-column>
			<el-table-column prop="updater" label="添加人" align="center"></el-table-column>
			<el-table-column label="操作" align="center">
				<template slot-scope="scope">
					<el-button size="mini" type="danger" @click="handleDelete(scope.row)">移出黑名单</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div class="pagination-container">
			<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.pageNum" :page-sizes="[10,20,30,50]" :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
		</div>
	</div>
</template>

<script>
	import { newWordList, batchDelete } from '../../../api/word'
	import pinyin from 'pinyin'

	export default {
		name: 'blackList',
		created() {
			this.getList()
		},
		methods: {
			handleSelectionChange(val) {
				this.multipleSelection = val.map(e => e.id)
			},
			getList() {
				this.listLoading = true
				newWordList(this.listQuery).then(res => {
					this.listLoading = false
					this.tableData = res.Data
					this.total = parseInt(res.total)
				})
			},
			handleSizeChange(val) {
				this.listQuery.pageSize = val
				this.getList()
			},
			handleCurrentChange(val) {
				this.listQuery.pageNum = val
				this.getList()
			},
			handleDeleteList() {
				if(this.multipleSelection.length === 0){
					this.$message({ type: 'warning', message: '请勾选需要移出黑名单的数据' })
				 	return
				}
				this.$confirm('确认移出黑名单, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					batchDelete({ 'batchIds': this.multipleSelection }).then(() => {
						this.getList()
						this.$notify({ title: '成功', message: '已移出黑名单', type: 'success', duration: 2000 })
					})
				}).catch(() => {
					this.$message({ type: 'info', message: '已取消' })
				})
			},
	      	handleDelete (row) {
		        this.$confirm('确认移出黑名单, 是否继续?', '提示', {
		          	confirmButtonText: '确定',
		          	cancelButtonText: '取消',
		          	type: 'warning'
		        }).then(() => {
		          batchDelete({ 'batchIds': [row.id] }).then(() => {
		            this.$notify({ title: '成功', message: '已移出黑名单', type: 'success', duration: 2000 })
		            this.getList()
		          })
		        }).catch(() => {
		          this.$message({ type: 'info', message: '已取消' })
		        })
	      	}
		},
		data() {
			return {
				multipleSelection: [],
				total: null,
				listLoading: false,
				listQuery: {
					pageNum: 1,
					pageSize: 20,
					dataStatus: 2,
					wordName:''
				},
				tableData: []
			}
		}
	}
</script>